##ENSURE SPREADSHEET IS FILTERED FIRST RUN_DATE (oldest to newest) then by DATETIME (oldest to newest)
# Points to background correct
good_id_mc3_bg<-c(68:75, 925:932, 236:238, 1093:1095, 265:267, 1122:1123, 1979, 1980, 1982, 280:283, 1137:1140, 1994:1997, 665:668, 1522:1527, 145:149, 1002:1006, 694, 695, 697, 795, 1551, 1552, 1554, 163, 164, 166, 167, 1020, 1021, 1022, 1877, 1878, 2408, 2409, 2411 )#350
# 85:91, 899:906, 235:237, 1049:1051, 265:268, 1079:1080, 1893, 1894, 1896, 280:283, 1908:1911, 667:670,672, 149:153, 963:967, 706:708, 1520:1522, 2334:2336, 167, 168, 170, 171, 981:984, 1795, 1796
good_id_mc3_fall<-c(291:293, 295, 297, 299, 302, 305, 307, 933:935, 1061:1063, 1065, 351, 352, 354, 356, 358, 360, 362, 429, 366, 368, 370, 1096:1107, 373, 375:379, 381, 382, 390, 391, 1126, 1128, 1129, 1983:1990, 392, 394, 395, 397, 399, 401:403, 1141, 1146, 1998:2003, 2058, 2060, 2061, 2063, 2064, 672, 674:681, 1641:1650, 627:635, 438, 424, 625, 626, 1007:1014, 1016:1019, 715, 718:724, 638:641, 663, 664, 810, 811, 812, 813, 814, 1028, 1047, 1048:1056, 1880:1881, 1885, 1904:1913, 1652:1665, 2509:2523, 2538) #350
# 301:309, 907:909, 1014:1016, 320, 351:360, 430, 1052:1063, 373, 375:379, 381:384, 1085:1086, 1898:1904, 385:387, 389:393, 1912:1917, 1950:1954, 674, 676:683, 627:632, 634:636, 972:975, 977:980, 716, 718, 719, 721, 723, 724, 638:643, 988:997, 1797, 1799:1811
# Points to background correct
good_id_mc_bg<- c(good_id_mc3_bg, 200:203, 222:224, 1057, 1058, 1060, 1079:1081, 235, 251, 252, 1092, 1108, 1109, 322:324, 1179:1181, 2036:2038, 337:340, 1194, 1195, 1197, 2197:2200, 642:644, 1499:1501, 174:177, 1031:1034, 520:523,1377:1381, 209, 211, 212, 1066, 1068, 1069, 2301:2305, 1923:1926) #450
# 205:208, 222:224, 1019,1020,1036:1038, 250:252, 1064:1066, 327:329, 1141,1143, 1955:1957, 483:486, 1156,1157, 1159, 2111:2114, 653:655, 184:187, 998:1001, 520:524, 1334:1338, 209, 211, 212, 1023:1026, 1837:1840
good_id_mc_fall<-c(good_id_mc3_fall, 818, 820, 821, 300, 301, 304, 306, 308, 309, 1082:1091, 353, 355, 357, 359, 361, 363, 364, 365, 367, 369, 371, 372, 1110:1121, 386, 387, 388, 389, 335, 336, 1182, 1183, 1187:1193, 2039:2050, 393, 415, 404, 405:409, 1198, 1345:1349, 1352, 2201, 2202:2210, 645:653,1693:1701, 654, 823, 656:662, 1035:1043, 593, 596:600, 602, 1384, 1385, 1390:1396, 2306:2313, 2315, 2316, 827:835, 1070:1078, 2541:2549) #450
# 310:313, 315:319, 1039:1048, 361:372, 1067:1069, 1381:1389, 397:400, 1145, 1149:1155, 1959:1969, 403:409, 1160:1161, 1162, 1304:1308, 1310, 1598, 2115, 2116, 655:664, 644:646, 648:652, 1003:1007, 1010, 1341:1349
good_id_mc<- c(good_id_mc_bg, good_id_mc_fall)
## # A tibble: 1 x 1
## n
## <int>
## 1 11
c4<-map(chem_clean_nest_mc$data, loc='450', plotChem)
c4[[1]]
c4[[2]]
c4[[3]]
c4[[4]]
c4[[5]]
c4[[6]]
c4[[7]]
c4[[8]]
### export for UNM team
# # data for UNM
# library(chron)
#
# cl_conc<-chem_clean_long_mc%>%
# filter(site == '450')%>%
# filter(date %in% ymd(c('2018-07-17' , '2018-07-19')))%>%
# filter(var =='Cl')%>%
# filter(MaxDL_flag == 'No')
#
# cl_times<-times(format(cl_conc$datetime, "%H:%M:%S"))
#
# cl_final<-cbind(cl_conc, cl_times)
#
# write_csv(cl_final,"data/out/cl_071718_071918_csu_ic-times.csv" )
## # A tibble: 16 x 5
## # Groups: date [8]
## date site Cl NO3 PO4
## <date> <chr> <dbl> <dbl> <dbl>
## 1 2018-06-26 350 0.0873 0.0697 NA
## 2 2018-06-26 450 0.112 0.213 NA
## 3 2018-06-28 350 0.100 0.211 NA
## 4 2018-06-28 450 0.0975 0.005 NA
## 5 2018-06-30 350 0.118 0.100 0.005
## 6 2018-06-30 450 0.0956 0.0334 0.005
## 7 2018-07-02 350 0.121 0.005 0.005
## 8 2018-07-02 450 0.168 0.0438 0.005
## 9 2018-07-17 350 0.165 0.00737 NA
## 10 2018-07-17 450 0.0830 0.0649 NA
## 11 2018-07-19 350 0.239 0.0551 NA
## 12 2018-07-19 450 0.211 0.0663 NA
## 13 2018-07-21 350 0.202 0.0634 0.005
## 14 2018-07-21 450 0.791 0.108 0.005
## 15 2018-07-23 350 0.320 0.0602 0.005
## 16 2018-07-23 450 0.190 0.214 0.320
#create dataset with bg_mean concentrations
chem_merge<- chem_clean_long_mc%>%
left_join(.,chem_mean_mc_bg)
## Joining, by = c("site", "var", "date")
# Subtract bg from raw value
library(chron)
## Warning: package 'chron' was built under R version 3.5.3
##
## Attaching package: 'chron'
## The following objects are masked from 'package:lubridate':
##
## days, hours, minutes, seconds, years
chem_corr<- chem_merge%>%
mutate(value_corr=value-bg_mean)
corr_times<-times(format(chem_corr$datetime, "%H:%M:%S"))
corr_final<-cbind(chem_corr, corr_times)
write_csv(corr_final,"data/out/chem_bg_corrected.csv")
#Create function to graph
plotChem_corr <- function (df, loc, value = value_corr) {
date_title<-date(df$datetime[[1]])
ggplot(dplyr::filter(df, site==loc), aes(datetime, value_corr),group = 1) +
geom_point(shape = 16, size = 3) +
geom_line() +
theme_few() +
facet_wrap( ~ var, ncol = 1, scale = 'free_y')+
labs(title = date_title)
}
chem_corr_nest<-chem_corr%>%
# filter(date %in% injdates)%>%
arrange(date)%>%
group_by(date)%>%
nest()
corr3<-map(chem_corr_nest$data, plotChem_corr, loc='350', value =chem_corr_nest$data$value_corr )
corr3[[1]]
corr3[[2]]
corr3[[3]]
corr3[[4]]
corr3[[5]]
corr3[[6]]
corr3[[7]]
corr3[[8]]
corr4<-map(chem_corr_nest$data, plotChem_corr, loc='450', value =chem_corr_nest$data$value_corr )
corr4[[1]]
corr4[[2]]
corr4[[3]]
corr4[[4]]
corr4[[5]]
corr4[[6]]
corr4[[7]]
corr4[[8]]